/*******************************************************************************
    Copyright 2006 Josh Edler
    
    This file is part of Loominate.

    Loominate is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Loominate is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Loominate; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*******************************************************************************/

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Loominate.Gooey.Controls
{
	/// <summary>
	/// Description of CloseTabButton.
	/// </summary>
	public class CloseTabButton : Button
	{
		private TabPage page;
		
		public CloseTabButton(TabPage page)
		{
			this.page = page;

			this.Text = "X";
			Graphics g = Graphics.FromHwnd(this.Handle);
			this.Width = (int) g.MeasureString(this.Text, this.Font).Width + 10;
			
			page.SizeChanged += new EventHandler(PageSizeChangedHandler);
			this.Click += new EventHandler(CloseTabClickHandler);
		}
		
		private void CloseTabClickHandler(object sender, EventArgs e)
		{
			page.Parent.Controls.Remove(page);
		}

		private void PageSizeChangedHandler(object sender, EventArgs e)
		{
			this.Left = page.Width - this.Width;
			this.Top = 0;
		}		
	}
}
